const mongoose = require('mongoose')
const config = {
  URL: 'mongodb://localhost:27017/window'
}
mongoose.connect(
  config.URL, //数据库集合地址'mongodb://127.0.0.1:27017/demo'
  { useNewUrlParser: true, useUnifiedTopology: true }//固定配置
)

const db = mongoose.connection
db.on('error', () => {
  console.log('== 数据库连接失败 ==')
})

db.on('open', () => {
  console.log('-- 数据库连接成功 --')
})

module.exports = {
  User: mongoose.model('user', require('./user')),
  Chat: mongoose.model('chat', require('./chat'))
}